<?php
	class kekhaigiaodichdb
	{
		public function Them($SoButToan = "",
							 $MaSoTietKiem = "",
							 $SoKheUoc = "",
							 $MaLoaiGiaoDich = 0,
							 $MaNguoiDung = "",
							 $NgayGiaoDich = "",
							 $SoTienTaiKhoanNo=0,
							 $SoTienTaiKhoanCo=0)
		{
			$sql = "INSERT INTO kekhaigiaodich(SoButToan, MaSoTietKiem, SoKheUoc, MaLoaiGiaoDich, MaNguoiDung, NgayGiaoDich, SoTienTaiKhoanNo, SoTienTaiKhoanCo)
					VALUES('$SoButToan', '$MaSoTietKiem', '$SoKheUoc', $MaLoaiGiaoDich, '$MaNguoiDung', '$NgayGiaoDich', $SoTienTaiKhoanNo, $SoTienTaiKhoanCo)";	
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($SoButToan = "",
								$MaSoTietKiem = "",
								$SoKheUoc = "",
							 	$MaLoaiGiaoDich = 0,
							 	$MaNguoiDung = "",
							 	$NgayGiaoDich = "",
								$SoTienTaiKhoanNo=0,
								$SoTienTaiKhoanCo=0)
		{
			$sql = "UPDATE kekhaigiaodich SET NgayGiaoDich = '$NgayGiaoDich'";
			
			if($SoButToan != "")
				$sql .= ", SoButToan = $SoButToan";
			
			if($MaSoTietKiem != "")
				$sql .= ", MaSoTietKiem = $MaSoTietKiem";
			
			if($SoKheUoc != "")
				$sql .= ", SoKheUoc = $SoKheUoc";
			
			if($MaNguoiDung != "")
				$sql .= ", MaNguoiDung = '$MaNguoiDung'";
			
			if($SoTienTaiKhoanNo > 0)
				$sql .= ", SoTienTaiKhoanNo = $SoTienTaiKhoanNo";
			
			if($SoTienTaiKhoanCo > 0)
				$sql .= ", SoTienTaiKhoanCo = $SoTienTaiKhoanCo";
			
			$sql .= " WHERE MaLoaiGiaoDich = $MaLoaiGiaoDich";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($SoButToan = "",
									$MaSoTietKiem = "",
									$SoKheUoc = "",
							 		$MaLoaiGiaoDich = 0,
							 		$MaNguoiDung = "",
							 		$NgayGiaoDich = "",
									$SoTienTaiKhoanNo=0,
									$SoTienTaiKhoanCo=0)
		{
			$sql = "SELECT * 
					FROM kekhaigiaodich
					WHERE (1)";
			
			if($SoButToan != "")
				$sql .= " AND SoButToan = '$SoButToan'";
			
			if($MaSoTietKiem != "")
				$sql .= " AND MaSoTietKiem = '$MaSoTietKiem'";
			
			if($SoKheUoc != "")
				$sql .= " AND SoKheUoc = '$SoKheUoc'";
			
			if($MaLoaiGiaoDich > 0)
				$sql .= " AND MaLoaiGiaoDich = $MaLoaiGiaoDich";
					
			if($MaNguoiDung != "")
				$sql .= " AND MaNguoiDung = '$MaNguoiDung'";
			
			if($NgayGiaoDich != "")
				$sql .= " AND NgayGiaoDich = '$NgayGiaoDich'";
			
			if($SoTienTaiKhoanNo > 0)
				$sql .= " AND SoTienTaiKhoanNo = $SoTienTaiKhoanNo";
				
			if($SoTienTaiKhoanCo > 0)
				$sql .= " AND SoTienTaiKhoanCo = $SoTienTaiKhoanCo";				
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function LayDanhSachTheoSoTietKiem($SoButToan = "",
				$MaSoTietKiem = "",
				$SoKheUoc = "",
				$MaLoaiGiaoDich = 0,
				$MaNguoiDung = "",
				$NgayGiaoDich = "",
				$SoTienTaiKhoanNo=0,
				$SoTienTaiKhoanCo=0)
		{
			$sql = "SELECT *
					FROM kekhaigiaodich
					WHERE SoKheUoc = ''";
				
			if($SoButToan != "")
				$sql .= " AND SoButToan = '$SoButToan'";
				
			if($MaSoTietKiem != "")
				$sql .= " AND MaSoTietKiem = '$MaSoTietKiem'";
				
			if($SoKheUoc != "")
				$sql .= " AND SoKheUoc = '$SoKheUoc'";
				
			if($MaLoaiGiaoDich > 0)
				$sql .= " AND MaLoaiGiaoDich = $MaLoaiGiaoDich";
				
			if($MaNguoiDung != "")
				$sql .= " AND MaNguoiDung = '$MaNguoiDung'";
				
			if($NgayGiaoDich != "")
				$sql .= " AND NgayGiaoDich = '$NgayGiaoDich'";
				
			if($SoTienTaiKhoanNo > 0)
				$sql .= " AND SoTienTaiKhoanNo = $SoTienTaiKhoanNo";
		
			if($SoTienTaiKhoanCo > 0)
				$sql .= " AND SoTienTaiKhoanCo = $SoTienTaiKhoanCo";
				
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function LayDanhSachTheoHopDongTinDung($SoButToan = "",
														$MaSoTietKiem = "",
														$SoKheUoc = "",
														$MaLoaiGiaoDich = 0,
														$MaNguoiDung = "",
														$NgayGiaoDich = "",
														$SoTienTaiKhoanNo=0,
														$SoTienTaiKhoanCo=0)
		{
			$sql = "SELECT *
					FROM kekhaigiaodich
					WHERE MaSoTietKiem = ''";
		
			if($SoButToan != "")
				$sql .= " AND SoButToan = '$SoButToan'";
		
			if($MaSoTietKiem != "")
				$sql .= " AND MaSoTietKiem = '$MaSoTietKiem'";
		
			if($SoKheUoc != "")
				$sql .= " AND SoKheUoc = '$SoKheUoc'";
		
			if($MaLoaiGiaoDich > 0)
				$sql .= " AND MaLoaiGiaoDich = $MaLoaiGiaoDich";
		
			if($MaNguoiDung != "")
				$sql .= " AND MaNguoiDung = '$MaNguoiDung'";
		
			if($NgayGiaoDich != "")
				$sql .= " AND NgayGiaoDich = '$NgayGiaoDich'";
		
			if($SoTienTaiKhoanNo > 0)
				$sql .= " AND SoTienTaiKhoanNo = $SoTienTaiKhoanNo";
		
			if($SoTienTaiKhoanCo > 0)
				$sql .= " AND SoTienTaiKhoanCo = $SoTienTaiKhoanCo";
		
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function LayDanhSachKhoangNgay($NgayBatDau = "", $NgayKetThuc = "")
		{
			$sql = "SELECT *
					FROM kekhaigiaodich
					WHERE NgayGiaoDich >= '$NgayBatDau' AND NgayGiaoDich <= '$NgayKetThuc'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function LayDanhSachKhoangNgaySoTietKiem($MaSoTietKiem="", $NgayBatDau = "", $NgayKetThuc = "")
		{
			$sql = "SELECT *
			FROM kekhaigiaodich
			WHERE MaSoTietKiem ='$MaSoTietKiem' AND NgayGiaoDich >= '$NgayBatDau' AND NgayGiaoDich <= '$NgayKetThuc'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function LayDanhSachKhoangNgayHopDongTinDung($SoKheUoc="", $NgayBatDau = "", $NgayKetThuc = "")
		{
			$sql = "SELECT *
			FROM kekhaigiaodich
			WHERE SoKheUoc ='$SoKheUoc' AND NgayGiaoDich >= '$NgayBatDau' AND NgayGiaoDich <= '$NgayKetThuc'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($SoButToan = "")
		{
			$sql = "DELETE 
					FROM kekhaigiaodich
					WHERE SoButToan = '$SoButToan'";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	}
?>